﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@model List<Three.BookStore.RBAC.DTOs.MenuDto>
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Three ERP系统</title>
    <link href="/Scripts/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <style>
        .layui-side-menu .layui-nav .layui-nav-item a {
            height: 40px;
            line-height: 40px;
            padding-left: 45px;
            padding-right: 30px;
        }
        .layui-side-menu .layui-nav .layui-nav-item .layui-icon {
            position: absolute;
            top: 50%;
            left: 20px;
            margin-top: -19px;
        }
        /* Tab样式 */
        .layui-tab {
            margin: 0;
        }
        .layui-tab-title .layui-this {
            background-color: #fff;
        }
        .layui-tab-title li {
            padding: 0 15px;
        }
        .layui-tab-title .layui-this:after {
            border-bottom-color: #fff;
        }
        .iframe-container {
            position: relative;
            height: calc(100vh - 112px);
            overflow: hidden;
        }
        .layui-tab-content {
            padding: 0;
            height: 100%;
            position: relative;
        }
        .layui-tab-item {
            height: 100%;
            width: 100%;
            position: relative;
        }
        iframe {
            width: 100%;
            height: 100%;
            border: none;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }
        /* 确保body和html有足够高度 */
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
        .layui-layout-admin {
            height: 100%;
        }
        .layui-body {
            overflow: hidden;
            bottom: 0;
        }
    </style>
</head>
<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo">ERP系统</div>
            <!-- 头部区域（可配合layui已有的水平导航） -->
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">
                    <a href="javascript:;">
                        <img src="~/images/logo/leptonxlite/r.jpg" class="layui-nav-img" />
                        管理员
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;">个人信息</a></dd>
                        <dd><a href="javascript:;">修改密码</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="/Home/Login">退出</a></li>
            </ul>
        </div>

        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll layui-side-menu">
                <!-- 左侧导航区域 -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test" lay-accordion="true">
                    @foreach (var menu in Model)
                    {
                    <li class="layui-nav-item">
                            <a href="@(string.IsNullOrEmpty(menu.Url) ? "javascript:;" : menu.Url)">
                                @if (!string.IsNullOrEmpty(menu.Icon))
                                {
                                    <i class="layui-icon @menu.Icon"></i>
                                }
                                <span>@menu.Name</span>
                            </a>
                            @if (menu.Children != null && menu.Children.Count > 0)
                            {
                                <dl class="layui-nav-child">
                                    @foreach (var subMenu in menu.Children)
                                    {
                                        if (subMenu.Children != null && subMenu.Children.Count > 0)
                                        {
                                            <dd>
                                                <a href="@(string.IsNullOrEmpty(subMenu.Url) ? "javascript:;" : subMenu.Url)">
                                                    @if (!string.IsNullOrEmpty(subMenu.Icon))
                                                    {
                                                        <i class="layui-icon @subMenu.Icon"></i>
                                                    }
                                                    <span>@subMenu.Name</span>
                                                </a>
                                <dl class="layui-nav-child">
                                                    @foreach (var childMenu in subMenu.Children)
                                                    {
                                                        <dd>
                                                            <a href="@(string.IsNullOrEmpty(childMenu.Url) ? "javascript:;" : childMenu.Url)">
                                                                @if (!string.IsNullOrEmpty(childMenu.Icon))
                                                                {
                                                                    <i class="layui-icon @childMenu.Icon"></i>
                                                                }
                                                                <span>@childMenu.Name</span>
                                                            </a>
                            </dd>
                                                    }
                                </dl>
                            </dd>
                                        }
                                        else
                                        {
                            <dd>
                                                <a href="@(string.IsNullOrEmpty(subMenu.Url) ? "javascript:;" : subMenu.Url)">
                                                    @if (!string.IsNullOrEmpty(subMenu.Icon))
                                                    {
                                                        <i class="layui-icon @subMenu.Icon"></i>
                                                    }
                                                    <span>@subMenu.Name</span>
                                                </a>
                            </dd>
                                        }
                                    }
                                </dl>
                            }
                    </li>
                    }
                </ul>
            </div>
        </div>

        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div class="layui-tab" lay-filter="demo" lay-allowclose="true">
                <ul class="layui-tab-title">
                    <li class="layui-this" lay-id="index">首页</li>
                </ul>
                <div class="layui-tab-content iframe-container">
                    <div class="layui-tab-item layui-show">
                        <iframe src="/Home/Welcome" frameborder="0" id="iframe_index" class="iframe-content"></iframe>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-footer">
            <!-- 底部固定区域 -->
            © Three.BookStore - ERP管理系统
        </div>
    </div>
    <script src="/Scripts/layui-v2.5.6/layui/layui.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        layui.use(['element', 'layer'], function(){
            var element = layui.element;
            var layer = layui.layer;
            var $ = layui.jquery;
            
            // 点击左侧菜单
            $('.layui-side a').on('click', function(e) {
                var href = $(this).attr('href');
                var menuName = $(this).find('span').text();
                
                if(href && href !== 'javascript:;') {
                    e.preventDefault(); // 阻止默认行为
                    
                    // 判断标签是否存在
                    var isExist = false;
                    var layId = href.replace(/\//g, '_').replace(/\./g, '_').replace(/\:/g, '_');
                    
                    $('.layui-tab-title li').each(function() {
                        if($(this).attr('lay-id') === layId) {
                            isExist = true;
                        }
                    });
                    
                    if(!isExist) {
                        // 新增一个Tab项
                        element.tabAdd('demo', {
                            title: menuName,
                            content: '<iframe src="' + href + '" frameborder="0" class="iframe-content" style="width:100%;height:100%;"></iframe>',
                            id: layId
                        });
                    }
                    
                    // 切换到指定Tab项
                    element.tabChange('demo', layId);
                }
            });
            
            // 监听选项卡切换
            element.on('tab(demo)', function(data){
                // 可以在这里添加tab切换时的其他操作
                // 刷新当前iframe内容
                var iframe = $('.layui-tab-content .layui-show iframe');
                if(iframe.length > 0) {
                    var src = iframe.attr('src');
                    iframe.attr('src', src);
                }
            });

            // 调整iframe高度
            function resizeIframe() {
                var height = $(window).height() - $('.layui-header').height() - $('.layui-footer').height() - $('.layui-tab-title').height() - 10;
                $('.iframe-container').height(height);
            }

            // 页面加载和窗口大小改变时调整iframe高度
            $(window).on('resize load', function() {
                resizeIframe();
            });
            resizeIframe();
        });
    </script>
</body>
</html>
